home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
wot-20080519-fx.xpi
/
chrome
/
wot.jar
/
content
/
pending.js
< prev
next >
Wrap
Text File
|
2007-11-11
|
4KB
|
192 lines
/*
pending.js
Copyright © 2005, 2006, 2007 Against Intuition, Inc. <info@mywot.com>
*/
var wot_pending =
{
init: function()
{
},
store: function(name) /* Hostname */
{
try {
if (!wot_cache.iscached(name) ||
!wot_cache.get(name, "pending")) {
return false;
}
var testimony_url = wot_cache.get(name, "testimony_url");
if (!testimony_url) {
return false;
}
var str = encodeURIComponent(
wot_url.replacehostname(
testimony_url,
wot_idn.utftoidn(name)))
dump("wot_pending.store: " + str + "\n");
for (var i = 0; i < WOT_APPLICATIONS; ++i) {
str += " " + wot_cache.get(name, "testimony_" + i);
}
var pending = "." + Date.now().toString();
return (wot_prefs.setChar("pending", wot_prefs.pending +
pending + " ") &&
wot_prefs.setChar("pending" + pending, str));
} catch (e) {
dump("wot_pending.store: failed with " + e + "\n");
}
return false;
},
clear: function(name) /* Preferences entry */
{
try {
if (!name || name.charAt(0) != '.') {
return;
}
dump("wot_pending.clear: clearing " + name + "\n");
/* Remove entry from preferences */
var pending = wot_prefs.pending.replace(RegExp(name), "");
pending = pending.replace(/^\s*/, ""); /* Leading whitespace */
var entry = "pending" + name;
if (wot_prefs.getChar(entry, null)) {
wot_prefs.clear(entry);
wot_prefs.clear(entry + ".submit");
wot_prefs.clear(entry + ".tries");
wot_prefs.setChar("pending", pending);
}
} catch (e) {
dump("wot_pending.clear: failed with " + e + "\n");
}
},
submit: function()
{
try {
var processing = wot_prefs.pending;
while (processing != "") {
/* Find an entry containing pending testimonies */
var result = /^\s*(\.\d+)\s*(.*)/.exec(processing);
if (!result || !result[1]) {
dump("wot_pending.submit: invalid format for: " +
processing + "\n");
break;
} else if (result[2]) {
processing = result[2];
} else {
processing = "";
}
var cn = result[1];
/* See if such entry exists and get its contents */
var content = wot_prefs.getChar("pending" + cn, null);
if (!content) {
continue;
}
/* Check status */
var submit = wot_prefs.getChar("pending" + cn + ".submit",
null);
if (submit && (Date.now() - Number(submit)) <
WOT_INTERVAL_SUBMIT_ERROR) {
/* Don't resubmit yet */
continue;
}
var tries = wot_prefs.getChar("pending" + cn + ".tries", null);
if (tries) {
tries = Number(tries);
if (tries >= WOT_MAX_TRIES_SUBMIT) {
this.clear(cn); /* Didn't work out... */
continue;
}
} else {
tries = 0;
}
/* Parse target URL */
var m = /^([^\s]+)(.*)/.exec(content);
if (!m || !m[1] || !m[2]) {
dump("wot_pending.submit: invalid entry: " + cn + "\n");
this.clear(cn);
continue;
}
var target = decodeURIComponent(m[1]);
if (!wot_url.ishostname(
wot_url.gethostname(target))) {
dump("wot_pending.submit: invalid entry: " + cn + "\n");
this.clear(cn);
continue;
}
/* Parse testimonies */
var testimonies = new Array();
content = m[2];
for (var j = 0; j < WOT_APPLICATIONS; ++j) {
m = /^\s*(-?\d+)(.*)/.exec(content);
if (!m || m[1] == null || Number(m[1]) < 0) {
testimonies[j] = -1;
} else if (Number(m[1]) > WOT_MAX_REPUTATION) {
testimonies[j] = WOT_MAX_REPUTATION;
} else {
testimonies[j] = Number(m[1]);
}
content = m[2];
}
dump("wot_pending.submit: found a pending testimony for " +
target + "\n");
/* Update status, submit testimonies */
wot_prefs.setChar("pending" + cn + ".submit",
Date.now().toString());
wot_prefs.setChar("pending" + cn + ".tries",
(tries + 1).toString());
wot_api_submit.send(cn, target, testimonies);
/* If there is cached data for this item, update cached
testimonies unless they have been already changed again */
var hostname = wot_url.gethostname(target);
if (wot_cache.iscached(hostname) &&
!wot_cache.get(hostname, "pending")) {
for (var k = 0; k < WOT_APPLICATIONS; ++k) {
if (testimonies[k] >= 0) {
wot_cache.set(hostname, "testimony_" + k,
testimonies[k]);
}
}
}
}
} catch (e) {
dump("wot_pending.submit: failed with " + e + "\n");
}
}
};
wot_pending.init();